<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>OGRE Meshes Exporter</title>
  <meta name="description" content="OGRE Meshes Exporter Manual">
  <meta name="keywords" content="OGRE, Blender, Export">
  <meta name="resource-type" content="document">
  <meta name="distribution" content="global">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link type="text/css" rel="stylesheet" href="style.css">
</head>

<body>
<div>
<h1>OGRE Meshes Exporter</h1>
<p>
Blender is an open source 3D content creation suite for modeling, animation, rendering and video post production. The OGRE Meshes Exporter is a set of python scripts to run directly within Blender. Currently it supports the export of
</p>
<ul>
  <li>
  mesh objects with vertex colours, multiple materials, uv textures and blend modes,
  </li>
  <li>
  armature keyframe animations,
  </li>
  <li>
  relative mesh shape animations.
  </li>
</ul>
<h2>Table of Contents</h2>
<ul>
  <li>
  <a href="#Installation">Installation</a>
  </li>
  <li>
  <a href="#Basic Usage">Basic Usage</a>
  <ul>
    <li>
    <a href="#Options">Options</a>
    </li>
  </ul>
  </li>
  <li>
  <a href="#Meshes">Meshes</a>
  </li>
  <li>
  <a href="#Materials">Materials</a>
  <ul>
    <li>
      <a href="#Rendering Materials">Rendering Materials</a>
    </li>
    <li>
      <a href="#Game Engine Materials">Game Engine Materials</a>
    </li>
    <li>
      <a href="#Custom Materials">Custom Materials</a>
    </li>
  </ul>
  </li>
  <li>
  <a href="#Animations">Animations</a>
  <ul>
    <li>
    <a href="#Armature Animations">Armature Animations</a>
    </li>
    <li>
    <a href="#Shape Animations">Shape Animations</a>
    </li>
  </ul>
  </li>
</ul>
<h2><a name="Installation">Installation</a></h2>
<p>
The script needs access to standard Python modules not shipped with Blender. Consult the Blender documentation at <a href="http://www.blender.org"> www.blender.org</a> how to incorporate Python with Blender.
</p>
<ul>
  <li>
  Copy the the script and all subdirectories either into ".blender/scripts" or the user defined scripts directory.
  </li>
  <li>
  In the "Scripts Window" run "Scripts &rarr; Update Menus".
  </li>
</ul>

<h2><a name="Basic Usage">Basic Usage</a></h2>
<p>
  There is a one-to-one correspondence:
</p>
<div class="importantBox">
  <div class="center">
    Blender Object (OB) &harr; Ogre::SceneNode
  </div>
  <div class="center">
    Blender Mesh (ME) &harr; Ogre::Entity
  </div>
</div>
<p>
  The OGRE Meshes Exporter maps Blender Meshes (ME) to Ogre Entities. Please refer to the OGRE Scene Exporter for the mapping of Blender Objects (OB) to Ogre SceneNodes.
</p>
<p>
To export Blender Meshes (ME) do:
</p>
<ul>
  <li>
  In the "3D View" select the mesh objects you want to export.
  </li>
  <li>
  In the "Scripts Window" run "Scripts &rarr; Export &rarr; OGRE Meshes".
  </li>
  <li>
  Choose your export options.
  </li>
  <li>
  Press the "Export" button.
  </li>
</ul>
<p>
You will get a detailed log of the export process. All files are exported in the OGRE XML format. Use the
OgreXMLConverter of your OGRE installation to convert the generated XML files to binary .mesh and .skeleton files.
</p>
<p>
<img src="images/meshesexporter.png" alt="exporter screenshot">
</p>
<p>Screenshot of the exporter interface.</p>

<h3><a name="Options"></a>Options</h3>
<dl compact="compact">
  <dt>Selected:</dt>
  <dd>The pop-up menu has an entry for every object that is selected for download. Select a mesh object in order to display its animation settings in the box below.
  <dl>
  <dt>Update</dt>
  <dd>Updates the list of all objects selected for export from the currently selected objects in the "3D View". Also updates the list of possible actions, deletes animations for removed actions and sets default animations for new actions.</dd>
  </dl>
  </dd>

  <dt>Animation Settings of</dt>
  <dd>Shows the animations that will be exported for the given mesh. You can switch between Skeleton, Pose and Morph animations, if available.
    <dl>
      <dt>Skeleton</dt>
      <dd>Show the skeleton animations, that will be exported. Only available if the mesh is modified via an armature either as parent or as modifier.</dd>

      <dt>Pose</dt>
      <dd>Show the pose animations, that will be exported. Only available if the mesh has shape keys.</dd>

      <dt>Morph</dt>
      <dd>Show the morph animations, that will be exported. Only available if the mesh has shape keys.</dd>
    </dl>
    Each line in the area with the scrollbar corresponds to an animation, that will be exported.
    <dl>
      <dt>Action name</dt>
      <dd>The name of the Blender action. Only available for skeleton animations.</dd>

      <dt>Start:</dt>
      <dd>Start frame of the animation.</dd>

      <dt>End:</dt>
      <dd>End frame of the animation.</dd>

      <dt>Animation export name</dt>
      <dd>The animation name in the exported OGRE file.</dd>

      <dt>Delete</dt>
      <dd>Removes the animation from export.</dd>

      <dt>Add</dt>
      <dd>Add another animation to be exported.</dd>
    </dl>
  </dd>

<dt>Material Settings</dt>
  <dd>
  <dl>
    <dt>Material File</dt>
    <dd>The name of the material script file that will be generated.</dd>
  
    <dt>Coloured Ambient</dt>
    <dd>Use scaled diffuse colour as ambient colour instead of scaled white.
This does only work for materials for which TexFace is not set.</dd>

    <dt>Copy Textures</dt>
    <dd>Copy textures to the export path, if possible</dd>

    <dt>Rendering Materials</dt>
    <dd>Export materials following the rendered result. (default)</dd>

    <dt>Game Engine Materials</dt>
    <dd>Export materials as displayed in the game engine.</dd>

    <dt>Custom Materials</dt>
    <dd>Export materials using specialised material templates.</dd>
  </dl>
  </dd>

  <dt>Fix Up Axis to Y</dt>
  <dd>Blender uses Z as up axis. This toggle switch allows changing the mesh to use Y as up axis.</dd>

  <dt>Require Materials</dt>
  <dd>Generate Error message when part of a mesh is not assigned with a material.</dd>

  <dt>Skeleton name follow mesh</dt>
  <dd>Force skeleton name to follow mesh name. Uncheck to make it use armature name instead.</dd>

  <dt>Apply Modifiers</dt>
  <dd>Apply mesh modifiers before export. This option is slow and may break vert order for morph targets. Not recommended for animated meshes.</dd>

  <dt>OgreXMLConverter</dt>
  <dd>Convert the XML files to binary files via the OgreXMLConverter. The exporter must be able to find the converter executable. You can specify its location in the preferences.</dd>

  <dt>Path</dt>
  <dd>All files of the exporter are written into this
directory. Mesh files are named after the mesh name in Blender with suffix ".mesh.xml". Skeleton files are named after the mesh object name and the armature name in Blender with suffix ".skeleton.xml".</dd>

  <dt>Export</dt>
  <dd>Export all objects in the list of objects selected for export.</dd>

  <dt>Preferences</dt>
  <dd>
  <dl>
    <dt>OgreXMLConverter</dt>
    <dd>
    <dl>
      <dt>Auto</dt>
      <dd>OgreXMLConverter is called without specifying its location. Only works if the executable is in the PATH.</dd>

      <dt>Manual</dt>
      <dd>Calls the executable specified in Converter.</dd>

      <dt>Export Options</dt>
      <dd>Please read XMLConverter documentation for more info.</dd>

      <dt>Additional arguments</dt>
      <dd>Additional arguments added to the converter call.</dd>
    </dl>
    </dd>
    
    <dt>Ok</dt>
    <dd>Apply changes.</dd>
    
    <dt>Cancel</dt>
    <dd>Discard changes.</dd>
  </dl>
  </dd>

  <dt>Help</dt>
  <dd>Display the manual in the default browser.</dd>

  <dt>Quit</dt>
  <dd>Exit from the export script.</dd>
</dl>

<p>The script loads and saves its options to a text buffer
"OgrePackage.cfg" inside the current .blend file. You can save the current settings, if you save the .blend file after quitting the exporter.
</p>

<h2><a name="Meshes">Meshes</a></h2>

<p>The script supports sticky and per face vertex uv coordinates,
smoothed and non-smoothed normals, vertex colours. Each rectangle face
is automatically converted into two triangle faces in the exported mesh. The exporter defaults to using 16 bit indices but if the submesh vertex count exceeds the 16 bit limit then 32 bit indices are used.</p>

<p>The script does not support subdivision surface (SubSurf) options.
To export a SubSurf object, you have to convert it into a Mesh object,
"Object &rarr; Convert Object Type... &rarr; Mesh (keep original)".</p>

<p>The script does not support the "Double Sided" mesh option, use the "Two Sided" face option instead.</p>

<p>To force the export of vertex colours, select "VCol Light" in the meshes' materials and export with "Game Engine Materials" disabled.
</p>

<h2><a name="Materials">Materials</a></h2>

<p>In contrast to OGRE, Blender treats material, uv texture and blend
mode separately. Also Blender distinguishes between material appearance
in the game engine and material appearance in the rendered results.
</p>

<h3><a name="Rendering Materials">Rendering Materials</a></h3>

<p>The name of the exported material is the same as in Blender. If the
"Two Sided" face option is set, the suffix "/TWOSIDE" is appended. If
the "TexFace" material option is set, the suffix "/TEXFACE" and the
name of the texture image that is assigned with the UV/Image Editor is
appended. The "Two Sided" face option has no effect in Blender's
rendering results and is evaluated on export for convenience only.
</p>

<p>
<img src="images/material.png" alt="material panel">
<img src="images/shaders.png" alt="shaders panel">
<img src="images/linksandpipeline.png" alt="links and pipeline panel">
</p>

Blender's material settings that affect the exported OGRE material are marked green.
<p>
<img src="images/image.png" alt="image panel">
</p>

<p>The script exports image textures with "Map Input" set to "UV" and
"Map To" set to "Col" and optional "Alpha". The supported image options
are marked green.
</p>

<table>
  <tbody>
    <tr>
    <th>InterPol</th>
    <th>MipMap</th>
    <th>resulting filtering</th>
  </tr>
  <tr>
    <td>yes</td>
    <td>yes</td>
    <td>trilinear</td>
  </tr>
  <tr>
    <td>yes</td>
    <td>no</td>
    <td>linear linear none</td>
  </tr>
  <tr>
    <td>no</td>
    <td>yes</td>
    <td>bilinear</td>
  </tr>
  <tr>
    <td>no</td>
    <td>no</td>
    <td>none</td>
  </tr>
  </tbody>
</table>

<h3><a name="Game Engine Materials">Game Engine Materials</a></h3>
The material name has to be unique. Therefore, the name of the exported
material consists of Blender's material name (if any), the face blend
mode and texture file name (if any). If vertex colours are defined, a
postfix "/VertCol" is appended. Also, if the two-sided face option is
set, "/TWOSIDE" is appended.

<p>If a material is assigned to face, only the properties that affect
the appearance in the game engine are exported. These are the "Col" and
"Spe" colours, the "Amb", "Spec" and "Hard" factors and the "VCol
Paint" and "TexFace" options.
</p>
Textures assigned with the UV/Image Editor are exported. Note that
material image textures, which can be exported as rendering engine
materials, give you more control over filtering and texture address
modes.

<p>
<img src="images/face.png" alt="face options">
</p>
<p>
Blender's face settings affect the mesh appearance only in the game
engine. The properties exported by the script are marked green.
</p>

<h3><a name="Custom Materials">Custom Materials</a></h3>
<p>
The default material export works very well for simple basic materials. However,
due to it's limitation, it is not feasable for any real projects. Most of the time
we develope specialized material with specialized shaders for a particular project.
In these circumstances, we would want to export the material files to our specialized
material and shader.
</p>

<p>
Hence, Custom Materials to the rescue. Custom Materials allows you to
provide template files which it will base on to generate your ideal material script.
</p>

<p>
To use it, first point the Template Path to a directory that is keeping your list of
material templates.
</p>

<p>
Each template file should be named with the .tpl extension
</p>

I.E. <em>phong.tpl</em>
<TABLE width="300px"><tr><td>&nbsp;</td><td class="example"><pre>
#import phong from "phong.material"

material %_materialName : phong
{
	set $diffuse %diffuse_tex
	set $normal %normal_tex
	set $spec %spec_tex
}
</pre></td></tr></table><P>

<p>
The above example uses the latest Ogre script feature(Shoggoth).
</p>

<p>
The format for the template is pretty straight forward. The first line of the template is reserved for import scripts.
This is done so that the import scripts will be placed at the begining of the generated material files. Duplicated import
scripts will also be removed.
</p>

<p>
The template uses key replacement to replace particular keys. The keys are defined as <code>%key</code> or <code>%{key}</code>.
The second version is for when you want to concatinate a template key with a fixed constant value; I.E. <code>%{diffuse_tex}.png</code>
</p>

<p>
In order to tell the exporter what template to use for each material, each material has to be assigned to a template.
This is done through the ID Property of the material. To access the ID Property, run "Help &rarr; ID Property Browser".
For more information about ID Property in blender, see: <a href="http://wiki.blender.org/index.php/BlenderDev/ID_Property">Blender's wiki on ID Property</a>
</p>

<img src="images/idproperty.png" alt="ID Property panel">
<p>
Above is an example of ID Property in use. The most important thing is to select the right context before we edit our ID Property.
Make sure the "Materials" category is selected. Then select your material (blue). Click on the "New" button to create a new property.
</p>

<p>
To make material assigned to a template, create a String property named template. The value of the property will be the template file
linking to this material. I.E. <em>phong</em> will point to <em>phong.tpl</em>
</p>

<p>
There are certain case where Blender's material does not support a particular custom property that is required of our custom material.
This is where custom properties come into play. As seen from the screen shot, it is possible to add custom properties to a material.
To do that, make sure you create a "properties" Subgroup.
</p>

<p>
What you do inside the "properties" Subgroup is up to you. The hirachy is maintained. To give an example:
</p>
<TABLE width="300px"><tr><td>&nbsp;</td><td class="example"><pre>
properties : Subgroup
  - someNumber = 123 : Int
  - someFloat = 0.234 : Float
  - someString = "Hello world" : String
  - someGroup : Subgroup
    - someIntArray = {1 2 3 4} : Int
    - someFloatArray = {0.1 0.2 0.3} : Float
</pre></td></tr></table><P>
<p>
From the above, to access these custom properties:
</p>
<TABLE width="300px"><tr><td>&nbsp;</td><td class="example"><pre>
%someNumber => 123
%someFloat => 0.234
%someString => Hello world
%someGroup.someIntArray => 1 2 3 4
%someGroup.someFloatArray => 0.1 0.2 0.3
</pre></td></tr></table><P>

<p>
Bellow are a list of default properties based on Blender's material.
</p>
<ul>
	<li>_materialName</li>
	<li>_ambient</li>
	<li>_diffuse</li>
	<li>_specular</li>
	<li>_emisive</li>
	<li>_scene_blend</li>
	<li>_depth_write</li>
	<li>_depth_func</li>
	<li>_receive_shadows</li>
	<li>_culling</li>
	<li>_lighting</li>
	<li>_fog_override</li>
	<li>(textureName)._texture</li>
	<li>(textureName)._tex_address_mode</li>
	<li>(textureName)._filtering</li>
	<li>(textureName)._colour_op</li>
	<li>(textureName)._sizeX</li>
	<li>(textureName)._sizeY</li>
	<li>(textureName)._sizeZ</li>
	<li>(textureName)._offsetX</li>
	<li>(textureName)._offsetY</li>
	<li>(textureName)._offsetZ</li>
</ul>

<p>
An important note on the (textureName). The texture name is the name defined in the Texture panel in the Material Buttons tab.
It follows the convension of how it is displayed in the Texture panel; I.E. <em>tex.123</em> gives <em>tex</em> while <em>tex.1a2</em> gives <em>tex.1a2</em>
</p>

<p>
On certain cases, one would prefer to use texture indexing instead of (textureName) access. That being the case, you can use the _tex[#] handle to access the texture by index.
I.E. <em>_tex[0]._filtering</em> will access the first texture's filtering mode.
</p>

<p>
Obviously, as the default properties shares the same library as the custom properties, you can actually use the custom properties to override the default properties.
If you need more default properties that are not provided but can be set from Blender material, please contact Lf3T-Hn4D through the forum.
</p>

<h2><a name="Animations">Animations</a></h2>
<p>
The animation speed in the export in terms of frames per second is taken from the corresponding scene render button.
</p>
<p>
<img src="images/format.png" alt="format panel">
</p>
<p>
Blender's format setting that affect the exported OGRE animation is marked green.
</p>
<h3><a name="Armature Animations">Armature Animations</a></h3>

<p>Armature animation export is available if the mesh has an armature as parent deform or an armature modifier and that armature has at least one action. Armature animations are exported based upon keyframe ranges and action names. You can choose any frame as start and end frame of an animation. In order to export armature animations of a mesh you don't have to select the armature
separately. On export, the script will sample the bone poses of the selected action frame by frame.
</p>
<ul>
<li>All vertices must be assigned to at least one bone.</li>
<li>In OGRE, you can have no more than four weighted bone assignments per mesh
vertex.</li>
<li>Note that OGRE does not inherit parent bone scaling by default.</li>
</ul>
<p>
<img src="images/armaturemodifier.png" alt="modifiers panel">
<img src="images/armatureparent.png" alt="modifiers panel">
</p>
<p>
The script supports a parented armature as well as an armature modifier.
</p>

<h3><a name="Shape Animations">Shape Animations</a></h3>
Relative shape animations can be exported as pose or morph animations. On export, the script will sample the vertex positions frame by frame.
<p>
<img src="images/relativeshape.png" alt="shape panel">
</p>
<p>
The script exports relative shape keys.
</p>
</div>
</body>
</html>
